 //
//  BBFunctionViewController.m
//  BearSiX
//
//  Created by Tom on 16/3/25.
//  Copyright © 2016年 Tom. All rights reserved.
//

#import "BBFunctionViewController.h"
#import "BBFouncCollectionCell.h"
#import "BBYRetailViewController.h"

#import "BBVIPViewController.h"
#import "BBAttireViewController.h"
#import "BBPhotodateViewController.h"
#import "BBPhotocustomerViewController.h"
#import "BBDresscustomerViewController.h"
#import "BBChoosepictureViewController.h"
#import "BBLookcustomerViewController.h"
#import "BBTakethingsViewController.h"
#import "BBYClientDataViewController.h"
#import "BBApplyViewController.h"
#import "BBWorkReportViewController.h"
#import "BBMyJobViewController.h"
#import "BBTodayProfitViewController.h"
#define HEADHEIGHT WINSIZEWIDTH/1.26
@interface BBFunctionViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
{
    UIImageView *_firstImage;
    UIImageView *_firstHeadView;
    UILabel *_firstHeadLabel;
    UILabel *_todayProfit;
    UILabel *_monthProfit;
    UIView *_headView;
    
    NSArray *_allCollecImages;
    NSArray *_allCollecTexts;
}
@property(nonatomic,strong)UICollectionView *collectionView;

@end

@implementation BBFunctionViewController


-(UICollectionView *)collectionView{

    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        flowLayout.minimumInteritemSpacing = 2;
        flowLayout.minimumLineSpacing = 2;
        [flowLayout setItemSize:CGSizeMake((WINSIZEWIDTH-2*3)/4, WINSIZEWIDTH/3.5)];
        [flowLayout setSectionInset:UIEdgeInsetsMake(0, 0, 0, 0)];
     //   [flowLayout setHeaderReferenceSize:CGSizeMake(WINSIZEWIDTH, WINSIZEWIDTH/1.5)];
        [flowLayout setScrollDirection:(UICollectionViewScrollDirectionVertical)];
        
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WINSIZEWIDTH, WINSIZEHEIGHT) collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = [UIColor colorWithHexString:@"f2f1fc"];
        _collectionView.delegate = self;
        _collectionView.dataSource =self;
    }
    return _collectionView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    self.title = @"应用宝";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"shezhi_y"] style:(UIBarButtonItemStyleDone) target:self action:@selector(setTingClick:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"saoyisao_y"] style:(UIBarButtonItemStyleDone) target:self action:@selector(saoYiSaoClick:)];
    [self.collectionView registerClass:[BBFouncCollectionCell class] forCellWithReuseIdentifier:@"founctionCell"];
    [self.view addSubview:self.collectionView];
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];

    [self initDataSource];
    [self initFirstView];
}
-(void)initFirstView{

    _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WINSIZEWIDTH, HEADHEIGHT-WINSIZEWIDTH/5)];
    _headView.backgroundColor = [UIColor whiteColor];
    _firstImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WINSIZEWIDTH, HEADHEIGHT-WINSIZEWIDTH/5)];
    _firstImage.backgroundColor = [UIColor colorWithHexString:@"dfe5e7"];
    _firstImage.image = [UIImage imageNamed:@"first_back_y"];
    _firstHeadView = [[UIImageView alloc]initWithFrame:CGRectMake(WINSIZEWIDTH/20, WINSIZEWIDTH/3.7, WINSIZEWIDTH/6, WINSIZEWIDTH/6)];
    _firstHeadView.image = [UIImage imageNamed:@"m_xingbie_y"];
    // _firstHeadView.backgroundColor = [UIColor redColor];
    _firstHeadView.layer.cornerRadius = _firstHeadView.height/2;
    _firstHeadView.layer.borderColor = [UIColor whiteColor].CGColor;
    _firstHeadView.layer.masksToBounds = YES;
    _firstHeadView.layer.borderWidth = 3;
    
    _firstHeadLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_firstHeadView.frame)+WINSIZEWIDTH/80, CGRectGetMaxY(_firstHeadView.frame)-_firstHeadView.height/2, WINSIZEWIDTH-CGRectGetMaxX(_firstHeadView.frame)*1.3, WINSIZEWIDTH/9)];
    _firstHeadLabel.textColor = [UIColor blackColor];
    _firstHeadLabel.font = [UIFont systemFontOfSize:WINSIZEWIDTH/22];
    _firstHeadLabel.text = @"北京施华洛婚纱摄影广渠门店";
    
    UIView *firstBackView = [[UIView alloc]initWithFrame:CGRectMake(0, _firstHeadLabel.y, WINSIZEWIDTH, _firstHeadLabel.height)];
    firstBackView.backgroundColor = [UIColor colorWithHexString:@"acacac"];
    firstBackView.alpha = 0.5;
    
    BButton *dayPBtn = [[BButton alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(firstBackView.frame), WINSIZEWIDTH/2, WINSIZEWIDTH/7.2) color:[UIColor whiteColor] style:(BButtonStyleBootstrapV3)];
    dayPBtn.layer.cornerRadius = 0;
    dayPBtn.layer.masksToBounds = YES;
    _todayProfit = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, WINSIZEWIDTH/2, dayPBtn.height-dayPBtn.height/4)];
    _todayProfit.text = @"￥2,800.00";
    _todayProfit.textColor = [UIColor colorWithHexString:@"ef6e64"];
    _todayProfit.font = [UIFont systemFontOfSize:WINSIZEWIDTH/20];
    _todayProfit.textAlignment = NSTextAlignmentCenter;
    UILabel *todayLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, dayPBtn.height-dayPBtn.height/2.3, _todayProfit.width, dayPBtn.height/2.5)];
    todayLabel.text = @"当日收益";
    todayLabel.font = [UIFont systemFontOfSize:WINSIZEWIDTH/27];
    todayLabel.textColor = [UIColor colorWithHexString:@"737373"];
    todayLabel.textAlignment = NSTextAlignmentCenter;
    [dayPBtn addSubview:_todayProfit];
    [dayPBtn addSubview:todayLabel];
    
    BButton *monthBtn = [[BButton alloc]initWithFrame:CGRectMake(WINSIZEWIDTH/2, dayPBtn.y, WINSIZEWIDTH/2, dayPBtn.height) color:[UIColor whiteColor] style:(BButtonStyleBootstrapV3)];
    _monthProfit = [[UILabel alloc]initWithFrame:_todayProfit.frame];
    _monthProfit.textAlignment = NSTextAlignmentCenter;
    _monthProfit.textColor = _todayProfit.textColor;
    _monthProfit.font = _todayProfit.font;
    _monthProfit.text = @"￥19,800.00";
    monthBtn.layer.masksToBounds = YES;
    monthBtn.layer.cornerRadius = 0;
    UILabel *monLabel = [[UILabel alloc]initWithFrame:todayLabel.frame];
    monLabel.text = @"当月收益";
    monLabel.textAlignment = NSTextAlignmentCenter;
    monLabel.font = todayLabel.font;
    monLabel.textColor = todayLabel.textColor;
    [monthBtn addSubview:_monthProfit];
    [monthBtn addSubview:monLabel];
    
    [_headView addSubview:_firstImage];
    [_headView addSubview:firstBackView];
    [_headView addSubview:_firstHeadView];
    [_headView addSubview:_firstHeadLabel];
    [_headView addSubview:dayPBtn];
    [_headView addSubview:monthBtn];
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{

    if (section==0) {
        return CGSizeMake(WINSIZEWIDTH, WINSIZEWIDTH/1.26);
    }else{
        return CGSizeMake(WINSIZEWIDTH, WINSIZEWIDTH/5);
    }
}

-(UICollectionReusableView*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

    UICollectionReusableView *reusableview = nil;
    NSArray *firstImage = @[@"gongzuo_y",@"bangong_y",@"tongji_y"];
    NSArray *firstText = @[@"工作流",@"办公流",@"统计流"];
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, _headView.height, WINSIZEWIDTH, HEADHEIGHT-_headView.height)];
    UIView *backView =[[UIView alloc]initWithFrame:CGRectMake(0, WINSIZEWIDTH/21, WINSIZEWIDTH, sectionView.height-WINSIZEWIDTH/21-2)];
    backView.backgroundColor = [UIColor whiteColor];
    CGFloat image_width = sectionView.height-WINSIZEWIDTH/21;
    UIImageView *leftImage = [[UIImageView alloc]initWithFrame:CGRectMake(image_width/4,image_width/4, image_width/2, image_width/2)];
   // leftImage.contentMode = UIViewContentModeScaleAspectFit;
    leftImage.image = [UIImage imageNamed:firstImage[indexPath.section]];
    
    UILabel *sectionTitle = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxY(leftImage.frame)+image_width/4, 0, WINSIZEWIDTH/1.5, backView.height)];
    sectionTitle.textColor = [UIColor blackColor];
    sectionTitle.font = [UIFont systemFontOfSize:WINSIZEWIDTH/22];
    sectionTitle.text = firstText[indexPath.section];
    [backView addSubview:leftImage];
    [backView addSubview:sectionTitle];
    [sectionView addSubview:backView];
    if (kind == UICollectionElementKindSectionHeader){
    
//       UICollectionReusableView *headView = [[UICollectionReusableView alloc]initWithFrame:CGRectMake(0, 0, WINSIZEWIDTH, WINSIZEWIDTH/1.7)];
       
        UICollectionReusableView  *view = nil;
        if (indexPath.section==0) {
     UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
            [headerView addSubview:_headView];
            [headerView addSubview:sectionView];
            view = headerView;
        }else{
            UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
            [headerView addSubview:backView];
            view = headerView;
        }
        if (indexPath.section==0) {
            view.size = CGSizeMake(WINSIZEWIDTH, _headView.height+sectionView.height);
        }else{
            view.size = sectionView.size;
        }
        return view;
//
//        NSString *title = [[NSString alloc] initWithFormat:@"Recipe Group #%i",indexPath.section +1];
//        
//        headerView.title.text = title;
//        
//        UIImage *headerImage = [UIImage imageNamed:@"header_banner.png"];
//        
//        headerView.backgroundImage.image = headerImage;
//
    
             // reusableview = (UICollectionReusableView*)_headView;
        //return view;
    }
    
//    if (kind == UICollectionElementKindSectionFooter){
//        
////        UICollectionReusableView *footerview = [collectionView dequeueResuableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
////        
////        reusableview = footerview;
//        
//    }
    
    return reusableview;
    
    
    
}
-(void)saoYiSaoClick:(UIBarButtonItem *)sender{

    
}
-(void)setTingClick:(UIBarButtonItem *)sender{

    
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 3;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    switch (section) {
        case 0:
            return 12;
            break;
            case 1:
            return 8;
            case 2:
            return 8;
            break;
        default:
            break;
    }
    return 0;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    BBFouncCollectionCell *cell = (BBFouncCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"founctionCell" forIndexPath:indexPath];
    cell.imageView.image = [UIImage imageNamed:_allCollecImages[indexPath.section][indexPath.row]];
    cell.itemLabel.text = _allCollecTexts[indexPath.section][indexPath.row];
    if(indexPath.section==2&&indexPath.row<5){
    
        cell.itemSecLabe.text = @"15787445456";
    }else{
    
        cell.itemSecLabe.text = @""; 
    }
    return cell;
}
#pragma mark -- collection dianji
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  
    BBYRetailViewController *retailVC = [BBYRetailViewController new];

    BBVIPViewController* vipVC=[BBVIPViewController new];
    BBAttireViewController* attVC=[BBAttireViewController new];
    BBPhotodateViewController* phoVC=[BBPhotodateViewController new];
    BBPhotocustomerViewController* pcusVC=[BBPhotocustomerViewController new];
    BBDresscustomerViewController* dressVC=[BBDresscustomerViewController new];
    BBChoosepictureViewController* chooseVC=[BBChoosepictureViewController new];
    BBLookcustomerViewController* choosepVC=[BBLookcustomerViewController new];
    BBTakethingsViewController *takethingstVC = [BBTakethingsViewController new];

    BBYClientDataViewController *clientVC = [BBYClientDataViewController new];
    
    BBApplyViewController *applyVC = [BBApplyViewController new];
    BBWorkReportViewController* workReportVC = [BBWorkReportViewController new];
    BBMyJobViewController* jobVC = [BBMyJobViewController new];
    BBTodayProfitViewController* bbtpVC = [BBTodayProfitViewController new];
    NSLog(@"++indexPath%@",indexPath);

    if (indexPath.section==0) {
        switch (indexPath.row) {
            case 0:
                [self.navigationController pushViewController:retailVC animated:YES];
                break;

            case 2:
                [self.navigationController pushViewController:phoVC animated:YES];
                break;
            case 4:
                [self.navigationController pushViewController:attVC animated:YES];
                break;
            case 5:
                [self.navigationController pushViewController:dressVC animated:YES];
                break;
            case 6:
                [self.navigationController pushViewController:pcusVC animated:YES];
                break;
            case 7:
                [self.navigationController pushViewController:chooseVC animated:YES];
                break;
            case 8:
                [self.navigationController pushViewController:choosepVC animated:YES];
                break;
            case 9:
                [self.navigationController pushViewController:takethingstVC animated:YES];
                break;
            
            case 11:
                [self.navigationController pushViewController:vipVC animated:YES];
                break;

                case 1:
                [self.navigationController pushViewController:clientVC animated:YES];
                break;
            default:
                break;
        }
    }else if (indexPath.section==1){
        switch (indexPath.row) {
            case 0:
                [self.navigationController pushViewController:applyVC animated:YES];
                
                break;
            case 1:
                
                [self.navigationController pushViewController:workReportVC animated:YES];
                break;
            case 2:
              
                
                break;
            case 3:
                [self.navigationController pushViewController:jobVC animated:YES];
                
                break;
                

            default:
                break;
        }
    
    }
    else if (indexPath.section==2){
        switch (indexPath.row) {
            case 0:
                [self.navigationController pushViewController:bbtpVC animated:YES];
                
            break;}
    }

    
}

-(void)initDataSource{

    _allCollecImages = @[
                         @[@"menshi_y",@"dingdan_y",@"sheying_y",@"yuyue_y",@"lifu_y",@"huazhuang_y",@"sheyingkehu_y",@"xuanpian_y",@"kanban_y",@"qvjian_y",@"kehu_y",@"vip_y"],
                         @[@"shenqing_y",@"gongzuobaobiao_y",@"kaoqin_y",@"woderenwu_y",@"kaoqinjilu_y",@"tongxunlu_y",@"",@"",@""],
                         @[@"dangriyingye_y",@"dangyueyingye_y",@"dangrichengjiaoliang_y",@"caiwushenhe_y",@"yingyebaobiao_y",@"",@"",@""]
                         ];
    _allCollecTexts = @[@[@"门市开单",@"订单详情",@"摄影排程",@"预约客户",@"礼服客户",@"化妆客户",@"摄影客户",@"选片客户",@"看版客户",@"取件客户",@"客户评价",@"VIP客户",@"",@"",@""],
                        @[@"申请",@"工作报表",@"考勤",@"我的任务",@"考勤记录",@"通讯录",@"",@"",@""],
                        @[@"当日营业",@"当月营业",@"当日成交量",@"财务审核",@"营业报表",@"",@"",@""]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
